#include <unistd.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <stdlib.h>

int main(){
  printf("testexec ... begin\n");
  pid_t id = fork();
  if(id==0){
    //child
    //我的父进程本身就有一批环境变量！！！，从bash来
    char *const argv[]={
      (char*)"mypragma",  
      NULL
    };
    char *const envp[]={
      (char*)"HAHA=111111111111",
      (char*)"hehe=222222222222",
      NULL
    };
    extern** environ; 
    printf("child pid:%d\n",getpid());
    sleep(2);
    execvpe("./mypragma",argv,envp);
    //execvpe("./mypragma",argv,environ);显示父进程的所有环境变量
    exit(1);
  }
  //father
  int status = 0;
  pid_t rid = waitpid(id,&status,0);
  if(rid>0){
    printf("father wait success,child exit code:%d\n",WEXITSTATUS(status));
  }
  printf("testexec ... end!\n");
  return 0;
}
